package patrol.mobile.com.mobilepatrol.activity.monitor;

import android.content.Context;
import android.os.Parcelable;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.CommonListActivity;
import patrol.mobile.com.mobilepatrol.bean.JiankkElefailrecEntity;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.JiankkElefailrecEntity;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

/**
 * Created by z on 2018/9/20.
 * Des:
 */

public class WeiXiuJiLuActivity extends CommonListActivity {

    @BindView(R.id.titleAddIcon)
    public ImageView titleAddIcon;
    private String id;
    private JiankkElefailrecEntity jiankkElefailrecEntity;

    @Override
    public void initTitle() {
        super.initTitle();
        titleAddIcon.setVisibility(View.VISIBLE);
    }


    @Override
    public void initData() {
        super.initData();
        id = getIntent().getStringExtra("id");
        titleAddIcon.setImageResource(R.mipmap.add);
        titleAddIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(v.getContext(), WxjuDetailActivity.class)
                        .putExtra("id", jiankkElefailrecEntity.getId()));
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        getHttpData();
    }

    private void getHttpData() {
        HashMap<String, String> hashMap = new HashMap();
        hashMap.put("id", id);
        HttpSender sender = new HttpSender(this, baseUrl, Urls.getJiankkElefailrecEntity);
        sender.requestPost(hashMap, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                Log.e("~~~~", response);
                jiankkElefailrecEntity = new Gson().fromJson(response, JiankkElefailrecEntity.class);
                mAdapter.updateItems(jiankkElefailrecEntity.getJiankkElefailrecDivList());
                mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        startActivity(new Intent(view.getContext(), WxjuDetailShowActivity.class)
                                .putExtra("id", jiankkElefailrecEntity.getJiankkElefailrecDivList().get(position).getId()));
                    }
                });
            }
        });
    }

    @Override
    protected BaseQuickAdapter initAdapter() {
        return new MyAdapter(this);
    }

    @Override
    protected String initTitleName() {
        return "维修记录";
    }

    public class MyAdapter extends BaseQuickAdapter<JiankkElefailrecEntity.JiankkElefailrecDivListBean> {

        public MyAdapter(Context context) {
            super(context);
        }

        @Override
        protected int attachLayoutRes() {
            return R.layout.item_weixiujilu_layout;
        }

        @Override
        protected void convert(BaseViewHolder holder, JiankkElefailrecEntity.JiankkElefailrecDivListBean item) {
            holder.setText(R.id.itenPostion, (jiankkElefailrecEntity.getJiankkElefailrecDivList().indexOf(item) + 1) + "");
            holder.setText(R.id.userName, "维护人:" + item.getRepairor());
            holder.setText(R.id.itemTime, item.getDate());

        }
    }
}